package com.example.com.daervideo.activitys.users;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.com.daervideo.R;
import com.example.com.daervideo.fragments.RenZhengFragment;

import java.util.ArrayList;

/**
 * Created by i7-1 on 2018/12/7.
 */

public class RenZhengActivity extends AppCompatActivity {
    private String[] tabIndicators = {"原创认证", "黄V认证", "蓝V认证"};
    private ArrayList<Fragment> fragments;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_renzheng);
        initView();
    }

    private void initView() {
        fragments = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            fragments.add(RenZhengFragment.newInstans(i));
        }

        TabLayout uTab = findViewById(R.id.r_tablyout);
        ViewPager uViewpager = findViewById(R.id.t_vp);
        uViewpager.setAdapter(new RAdapter(getSupportFragmentManager()));
        uTab.setTabMode(TabLayout.MODE_FIXED);
        uTab.setTabTextColors(getResources().getColor(R.color.gray), getResources().getColor(R.color.white));
        uTab.setSelectedTabIndicatorHeight(4);
        uTab.setSelectedTabIndicatorColor(Color.WHITE);
        ViewCompat.setElevation(uTab, 10);
        uTab.setupWithViewPager(uViewpager);
        for (int i = 0; i < tabIndicators.length; i++) {
            TabLayout.Tab itemTab = uTab.getTabAt(i);
            if (itemTab != null) {
                itemTab.setCustomView(R.layout.item_tab_layout_renzheng);
                TextView itemTv = (TextView) itemTab.getCustomView().findViewById(R.id.tv_menu_item);
                ImageView img = (ImageView) itemTab.getCustomView().findViewById(R.id.renzheng_img);
                itemTv.setText(tabIndicators[i]);
                if (i == 0) {
                    img.setImageResource(R.mipmap.original);
                } else if (i == 1) {
                    img.setImageResource(R.mipmap.yellow);
                } else {
                    img.setImageResource(R.mipmap.blue);
                }

            }
        }
    }

    private class RAdapter extends FragmentPagerAdapter {
        public RAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }


    }
}
